package com.jacarrichan.demo.dipper.handler;

import com.jacarrichan.demo.dipper.dao.po.CustomerPo;
import com.jacarrichan.demo.dipper.dao.service.IDaoService;
import com.jacarrichan.demo.dipper.model.CustomerDto;
import com.pactera.dipper.core.AbstractDipperHandler;
import com.pactera.dipper.core.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Jacarri on 2016-10-11.
 */
@Component
public class CustomerServiceAddHandler extends AbstractDipperHandler<CustomerDto> {
    private final Logger LOG = LoggerFactory.getLogger(getClass());
    @Autowired
    private IDaoService daoService;

    @Override
    public CustomerDto execute(CustomerDto dto, Message message) throws Exception {
        LOG.error("error", "execute ------------------------------");
        CustomerPo po = new CustomerPo();
        List<CustomerPo> result = daoService.selectList(po);
        po = (result.size() > 0 ? result.get(0) : null);
        dto.setPo(po);
        return dto;
    }
}
